package com.xinyin.aiqinhaiback.controller;

import com.serotonin.modbus4j.exception.ErrorResponseException;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.xinyin.aiqinhaiback.common.ResponseResult;
import com.xinyin.aiqinhaiback.model.entity.Param;
import com.xinyin.aiqinhaiback.service.HandleStrategy;
import com.xinyin.aiqinhaiback.service.InformationService;
import com.xinyin.aiqinhaiback.service.handStrategy.HandleStrategyFactory;
import com.xinyin.aiqinhaiback.service.handStrategy.StrategyContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/SourceConfig")
public class SourceConfigController {

	@Resource
	private  InformationService informationService;
	@Resource
	private StrategyContext strategyContext;

	/**
	 * 0 热源  1冷源
	 * @param type
	 * @return
	 * @throws ModbusTransportException
	 * @throws ErrorResponseException
	 * @throws ModbusInitException
	 */

	@PostMapping("/getSourceConfig")
	public ResponseResult test2(@RequestBody  Param param) throws Exception {
		HandleStrategy strategy = HandleStrategyFactory.getHandleStrategy(param.getType());
		//设置策略
		strategyContext.setReceiptHandleStrategy(strategy);
		//执行策略
		return strategyContext.selectConfig(param);
	}

	@PostMapping("/updateSourceConfig")
	public ResponseResult test(@RequestBody  Param param) {
//		HandleStrategy strategy = HandleStrategyFactory.getHandleStrategy(param.getType());
//		//设置策略
//		strategyContext.setReceiptHandleStrategy(strategy);
		//执行策略
		return strategyContext.updateConfig(param);
	}

//	@GetMapping("/getThermalData")
//	private ResponseResult<List<InformationModel>> getThermalData (){
//		return informationService.getThermalData();
//	}
//





}
